package com.pe1n.yangtaopai.page.find.presenter;

import com.pe1n.yangtaopai.bean.FindGoodsBean;
import com.pe1n.yangtaopai.page.find.modle.IModle;
import com.pe1n.yangtaopai.page.find.modle.ModleImpl;
import com.pe1n.yangtaopai.page.find.view.interfacese.IView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Pe1n on 2016/11/27.
 */

public class PresenterImpl implements IPresenter {

    private IModle mModle;
    private IView mView;

    public PresenterImpl(IView mView) {
        this.mView = mView;
        this.mModle = new ModleImpl();
    }

    @Override
    public void loadFindGoodsBeanData(String url) {
        mModle.getFindGoodsBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FindGoodsBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                    }

                    @Override
                    public void onNext(FindGoodsBean findGoodsBean) {
                        mView.loadFindGoodsBeanData(findGoodsBean);
                    }
                });
    }
}
